<template>
  <el-dialog v-bind:title="title" :visible.sync="dialogFormVisible">
    <el-form :model="form" name="el-form-goods-category-edit-name" id="el-form-goods-category-edit-id">
      <el-form-item label="供应商名称" :label-width="formLabelWidth">
        <el-input v-model="form.name" name="username" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="供应商编码" :label-width="formLabelWidth">
        <el-input v-model="form.code"  name="password" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="联系人" :label-width="formLabelWidth">
        <el-input v-model="form.contact"  name="password" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="联系地址" :label-width="formLabelWidth">
        <el-input v-model="form.address"  name="password" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="联系电话" :label-width="formLabelWidth">
        <el-input v-model="form.tel"  name="password" autocomplete="off"></el-input>
      </el-form-item>


      <el-form-item label="邮箱" :label-width="formLabelWidth">
        <el-input v-model="form.mail"  name="password" autocomplete="off"></el-input>
      </el-form-item>


      <el-form-item label="备注" :label-width="formLabelWidth">
        <el-input v-model="form.remark"  name="password" autocomplete="off"></el-input>
      </el-form-item>


    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="_ok">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>

    export default {

        name: "SysUserEdit",
      data(){
          return{

            formAdd:{
              name:'',
              code:'',
              contact:'',
              address:'',
              tel:'',
              mail:'',
              remark:'',
            },
            form:{
              name:'',
              code:'',
              contact:'',
              address:'',
              tel:'',
              mail:'',
              remark:'',
            },
            dialogFormVisible: false,

            formLabelWidth: '120px',
            title:''
          }
      },
      methods:{

          _open(obj){
            if (undefined===obj){
              this.title='添加供应商';
              this.form= JSON.parse(JSON.stringify(this.formAdd));;
              console.log('-----formAdd------',this.formAdd)
              this.dialogFormVisible=true;
            }else{
              this.title='编辑供应商';
              this.form=obj;
              this.dialogFormVisible=true;
            }

          },
          _ok(){
            let userData= this.form;
            if (undefined === userData.id){
              this.$http.post('/t_supplier/add',userData).then(res=>{

                console.log('res----------------',res)

                this.$message({
                  type: 'success',
                  message: '添加成功!'
                });
                this.$emit('on-result-change')
                this.dialogFormVisible = false;

              }).catch(err=>{
                this.$message({
                  type: 'info',
                  message: '添加失败'
                });
              })

            } else {
              this.$http.put('/t_supplier/'+userData.id,userData).then(res=>{
                this.$message({
                  type: 'success',
                  message: '编辑成功!'
                });
                this.$emit('on-result-change')
                this.dialogFormVisible = false;

              }).catch(err=>{
                this.$message({
                  type: 'info',
                  message: '编辑失败'
                });
              })
            }




          }

      },
    }
</script>

<style scoped>

</style>
